<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="&amp;#x524D;&amp;#x8A00;&amp;#x76F8;&amp;#x4FE1;&amp;#x7528;&amp;#x8FC7;&amp;#x5DE5;&amp;#x5177;&amp;#x7C7B;&amp;#x7684;&amp;#x5404;&amp;#x4F4D;&amp;#x4EC1;&amp;#x5144;&amp;#x90FD;&amp;#x89C9;&amp;#x5F97;&amp;#x5DE5;&amp;#x5177;&amp;#x7C7B;&amp;#x597D;&amp;#x7528;&amp;#xFF0C;&amp;#x5C0F;&amp;#x5F1F;">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 工具类">
<meta property="og:url" content="http://yoursite.com/2019/08/21/Android-工具类/index.html">
<meta property="og:site_name" content="Silence潇湘夜雨">
<meta property="og:description" content="&amp;#x524D;&amp;#x8A00;&amp;#x76F8;&amp;#x4FE1;&amp;#x7528;&amp;#x8FC7;&amp;#x5DE5;&amp;#x5177;&amp;#x7C7B;&amp;#x7684;&amp;#x5404;&amp;#x4F4D;&amp;#x4EC1;&amp;#x5144;&amp;#x90FD;&amp;#x89C9;&amp;#x5F97;&amp;#x5DE5;&amp;#x5177;&amp;#x7C7B;&amp;#x597D;&amp;#x7528;&amp;#xFF0C;&amp;#x5C0F;&amp;#x5F1F;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-07-19T05:31:59.806Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android 工具类">
<meta name="twitter:description" content="&amp;#x524D;&amp;#x8A00;&amp;#x76F8;&amp;#x4FE1;&amp;#x7528;&amp;#x8FC7;&amp;#x5DE5;&amp;#x5177;&amp;#x7C7B;&amp;#x7684;&amp;#x5404;&amp;#x4F4D;&amp;#x4EC1;&amp;#x5144;&amp;#x90FD;&amp;#x89C9;&amp;#x5F97;&amp;#x5DE5;&amp;#x5177;&amp;#x7C7B;&amp;#x597D;&amp;#x7528;&amp;#xFF0C;&amp;#x5C0F;&amp;#x5F1F;">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/08/21/Android-工具类/">





  <title>Android 工具类 | Silence潇湘夜雨</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Silence潇湘夜雨</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Android开发一枚</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home //首页"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user //关于"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags  //标签"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th //分类"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive //归档"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-schedule">
          <a href="/schedule/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar //日程表"></i> <br>
            
            日程表
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap //站点地图"></i> <br>
            
            站点地图
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/21/Android-工具类/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Silence潇湘夜雨">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Silence潇湘夜雨">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android 工具类</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-08-21T15:51:43+08:00">
                2019-08-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/工具类/" itemprop="url" rel="index">
                    <span itemprop="name">工具类</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  7.9k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  49
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="&#x524D;&#x8A00;"><a href="#&#x524D;&#x8A00;" class="headerlink" title="&#x524D;&#x8A00;"></a>&#x524D;&#x8A00;</h3><p><strong>&#x76F8;&#x4FE1;&#x7528;&#x8FC7;&#x5DE5;&#x5177;&#x7C7B;&#x7684;&#x5404;&#x4F4D;&#x4EC1;&#x5144;&#x90FD;&#x89C9;&#x5F97;&#x5DE5;&#x5177;&#x7C7B;&#x597D;&#x7528;&#xFF0C;&#x5C0F;&#x5F1F;&#x4E0D;&#x624D;&#xFF0C;&#x4ECA;&#x5929;&#x6597;&#x80C6;&#x62FF;&#x51FA;&#x81EA;&#x5DF1;&#x611F;&#x89C9;&#x6BD4;&#x8F83;&#x987A;&#x624B;&#x7684;&#x5DE5;&#x5177;&#x7C7B;&#x3002;</strong></p>
<hr>
<p>##1&#x3001;Activity&#x63A7;&#x5236;&#x7C7B;</p>
<pre><code>public class ActivityCollector{
    //activity&#x96C6;&#x5408;
 public static List&lt;Activity&gt; mActList = new ArrayList&lt;Activity&gt;();
        /**
          * &#x6DFB;&#x52A0;Activity
          * 
          * @param activity
          */

   public static void addActivity(Activity activity){
      mActList.add.add(activity);
    }
    }
         /**
           * &#x79FB;&#x9664;Activity
           */
          public static void removeActivity(Activity activity) {
            mActList.remove(activity);
         }

        /**
          * &#x9000;&#x51FA;
          */
         public static void finishAll() {
            for (Activity activity : mActList) {
              if (!activity.isFinishing()) {

                  activity.finish();
           }
         }
       }

}</code></pre><h2 id="2&#x3001;&#x5E94;&#x7528;&#x5E02;&#x573A;&#x7BA1;&#x7406;&#x7C7B;"><a href="#2&#x3001;&#x5E94;&#x7528;&#x5E02;&#x573A;&#x7BA1;&#x7406;&#x7C7B;" class="headerlink" title="2&#x3001;&#x5E94;&#x7528;&#x5E02;&#x573A;&#x7BA1;&#x7406;&#x7C7B;"></a>2&#x3001;&#x5E94;&#x7528;&#x5E02;&#x573A;&#x7BA1;&#x7406;&#x7C7B;</h2><pre><code>  public class MarketUtils {
     // 360&#x624B;&#x673A;&#x52A9;&#x624B;
    public static final String MARKET = &quot;com.qihoo.appstore&quot;;
    // &#x6DD8;&#x5B9D;&#x624B;&#x673A;&#x52A9;&#x624B;
    public static final String MARKET_TAOBAO = &quot;com.taobao.appcenter&quot;;
    // &#x5E94;&#x7528;&#x5B9D;
    public static final String MARKET_QQDOWNLOADER = &quot;com.tencent.Android.qqdownloader&quot;;
    // &#x5B89;&#x5353;&#x5E02;&#x573A;
    public static final String MARKET_HIAPK = &quot;com.hiapk.marketpho&quot;;
    // &#x5B89;&#x667A;&#x5E02;&#x573A;
    public static final String MARKET_GOAPK = &quot;cn.goapk.market&quot;;
    // &#x5305;&#x540D;
    public static final String APP_PACKAGE_NAME = &quot;com.*.*&quot;;

   public MarketUtils() {
    throw new AssertionError();
}
  /**
    * &#x8DF3;&#x8F6C;&#x5230;&#x5E94;&#x7528;&#x5E02;&#x573A;
    * 
    * @param appPkg
    *            &#xFF1A;&#x4E0A;&#x4F20;&#x5230;&#x5E94;&#x7528;&#x5E02;&#x573A;&#x4E0A;app&#x7684;&#x5305;&#x540D;,&#x4E0D;&#x662F;&#x672C;&#x9879;&#x76EE;&#x7684;&#x5305;&#x540D;
    * @param marketPkg
    *            &#xFF1A;&#x5E94;&#x7528;&#x5E02;&#x573A;&#x7684;&#x5305;&#x540D;
    */
    public static void goToMarket(Context context, String packageName) {
    Uri uri = Uri.parse(&quot;market://details?id=&quot; + packageName);
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    try {
        context.startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
    }
}

   /**
     * &#x542F;&#x52A8;App
     * 
     * @param context
     */
   public static void launchapp(Context context) {
    // &#x5224;&#x65AD;&#x662F;&#x5426;&#x5B89;&#x88C5;&#x8FC7;App&#xFF0C;&#x5426;&#x5219;&#x53BB;&#x5E02;&#x573A;&#x4E0B;&#x8F7D;
    if (isAppInstalled(context, APP_PACKAGE_NAME)) {
        context.startActivity(context.getPackageManager()
            .getLaunchIntentForPackage(APP_PACKAGE_NAME));
    } else {
        goToMarket(context, APP_PACKAGE_NAME);
    }
}

     /**
       * &#x68C0;&#x6D4B;&#x67D0;&#x4E2A;&#x5E94;&#x7528;&#x662F;&#x5426;&#x5B89;&#x88C5;
       * 
       * @param context
       * @param packageName
       * @return
       */
   public static boolean isAppInstalled(Context context, String packageName) {
    try {
        context.getPackageManager().getPackageInfo(packageName, 0);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}
    /**
       * &#x5224;&#x65AD;&#x5E02;&#x573A;&#x662F;&#x5426;&#x5B58;&#x5728;&#x7684;&#x65B9;&#x6CD5;
       * 
       * @param context
       * @param packageName
       *            &#x5E94;&#x7528;&#x5E02;&#x573A;&#x5305;&#x540D;
       * @return true or false
       */
  public static boolean isAvilible(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();// &#x83B7;&#x53D6;packagemanager
    List&lt;PackageInfo&gt; packageInfo = packageManager.getInstalledPackages(0);// &#x83B7;&#x53D6;&#x6240;&#x6709;&#x5DF2;&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;&#x7684;&#x5305;&#x4FE1;&#x606F;
    List&lt;String&gt; NameList = new ArrayList&lt;String&gt;();// &#x7528;&#x4E8E;&#x5B58;&#x50A8;&#x6240;&#x6709;&#x5DF2;&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;&#x7684;&#x5305;&#x540D;
    // &#x4ECE;packageInfo&#x4E2D;&#x53D6;&#x51FA;&#x5305;&#x540D;&#xFF0C;&#x653E;&#x5165;NameList&#x4E2D;
    if (packageInfo != null) {
        for (int i = 0; i &lt; packageInfo.size(); i++) {
            String pn = packageInfo.get(i).packageName;
            NameList.add(pn);
        }
    }
    return NameList.contains(packageName);// &#x5224;&#x65AD;pName&#x4E2D;&#x662F;&#x5426;&#x6709;&#x76EE;&#x6807;&#x7A0B;&#x5E8F;&#x7684;&#x5305;&#x540D;&#xFF0C;&#x6709;TRUE&#xFF0C;&#x6CA1;&#x6709;FALSE
}
 } </code></pre><h2 id="3&#x3001;Toast&#x5DE5;&#x5177;&#x7C7B;&#xFF08;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#xFF0C;&#x8BF7;&#x770B;&#x53E6;&#x5916;&#x4E00;&#x7BC7;-Android-&#x81EA;&#x5B9A;&#x4E49;Toast&#xFF0C;&#x5E76;&#x4E14;&#x52D8;&#x8BEF;"><a href="#3&#x3001;Toast&#x5DE5;&#x5177;&#x7C7B;&#xFF08;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#xFF0C;&#x8BF7;&#x770B;&#x53E6;&#x5916;&#x4E00;&#x7BC7;-Android-&#x81EA;&#x5B9A;&#x4E49;Toast&#xFF0C;&#x5E76;&#x4E14;&#x52D8;&#x8BEF;" class="headerlink" title="3&#x3001;Toast&#x5DE5;&#x5177;&#x7C7B;&#xFF08;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#xFF0C;&#x8BF7;&#x770B;&#x53E6;&#x5916;&#x4E00;&#x7BC7;[Android &#x81EA;&#x5B9A;&#x4E49;Toast&#xFF0C;&#x5E76;&#x4E14;&#x52D8;&#x8BEF;"></a>3&#x3001;<del>Toast&#x5DE5;&#x5177;&#x7C7B;</del>&#xFF08;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#xFF0C;&#x8BF7;&#x770B;&#x53E6;&#x5916;&#x4E00;&#x7BC7;[Android &#x81EA;&#x5B9A;&#x4E49;Toast&#xFF0C;&#x5E76;&#x4E14;&#x52D8;&#x8BEF;</h2><p>Android&#x5DE5;&#x5177;&#x7C7B;&#x91CC;&#x9762;&#x7684;ToastUtils]()&#xFF09;<br>&#x200B;      public class ToastUtils {~<br>&#x200B;       public static Toast toast;<br>&#x200B;       public static boolean isShow = true;</p>
<pre><code>   private ToastUtils() {
    // &#x4E0D;&#x80FD;&#x88AB;&#x5B9E;&#x4F8B;&#x5316;
    throw new UnsupportedOperationException(&quot;cannot be instantiated&quot;);
}

    public static void showToast(Context context, String message) {
    if (toast == null) {
        toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    } else {
        toast.setText(message);
    }
    toast.show();
}
/**
 * &#x5C4F;&#x5E55;&#x4E2D;&#x95F4;&#x4F4D;&#x7F6E;&#x663E;&#x793A;&#x77ED;&#x65F6;&#x95F4;Toast
 * 
 * @param context
 * @param msg
 */
public static void ToastShortCenter(Context context, String msg) {
    if (isShow) {
        if (context != null) {
            Toast toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    }

}

/**
 * &#x5C4F;&#x5E55;&#x4E2D;&#x5FC3;&#x4F4D;&#x7F6E;&#x957F;&#x65F6;&#x95F4;&#x663E;&#x793A;Toast
 * 
 * @param context
 * @param message
 */
public static void ToastLongCenter(Context context, String message) {
    if (isShow) {
        if (context != null) {
            Toast toast = Toast.makeText(context, message,
                    Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    }
}

/**
 * &#x81EA;&#x5B9A;&#x4E49;&#x663E;&#x793A;Toast&#x65F6;&#x95F4;
 * 
 * @param context
 * @param message
 * @param duration
 */
public static void ToastShow(Context context, String message, int duration) {
    if (isShow)
        Toast.makeText(context, message, duration).show();
}
}</code></pre><h2 id="4&#x3001;KeyBoardUtils"><a href="#4&#x3001;KeyBoardUtils" class="headerlink" title="4&#x3001;KeyBoardUtils"></a>4&#x3001;KeyBoardUtils</h2><p>&#x200B;      public class KeyBoardUtils {</p>
<pre><code>public KeyBoardUtils() {
    throw new AssertionError();
}

/**
 * &#x6253;&#x5361;&#x8F6F;&#x952E;&#x76D8;
 * 
 * @param mEditText
 *            &#x8F93;&#x5165;&#x6846;
 * @param mContext
 *            &#x4E0A;&#x4E0B;&#x6587;
 */
public static void openKeybord(EditText mEditText, Context mContext) {
    InputMethodManager imm = (InputMethodManager) mContext
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
            InputMethodManager.HIDE_IMPLICIT_ONLY);
}

/**
 * &#x5173;&#x95ED;&#x8F6F;&#x952E;&#x76D8;
 * 
 * @param mEditText
 *            &#x8F93;&#x5165;&#x6846;
 * @param mContext
 *            &#x4E0A;&#x4E0B;&#x6587;
 */
public static void closeKeybord(EditText mEditText, Context mContext) {
    InputMethodManager imm = (InputMethodManager) mContext
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
}
}</code></pre><h2 id="5&#x3001;AES&#x5DE5;&#x5177;&#x7C7B;"><a href="#5&#x3001;AES&#x5DE5;&#x5177;&#x7C7B;" class="headerlink" title="5&#x3001;AES&#x5DE5;&#x5177;&#x7C7B;"></a>5&#x3001;AES&#x5DE5;&#x5177;&#x7C7B;</h2><p>&#x200B;      public class AESUtils {</p>
<pre><code>// &#x5BC6;&#x94A5;&#x7B97;&#x6CD5;
private static final String KEY_ALGORITHM = &quot;AES&quot;;
// AES/CBC/PKCS7Padding &#x5206;&#x522B;&#x5BF9;&#x5E94; &#x52A0;&#x5BC6;||&#x89E3;&#x5BC6;&#x7B97;&#x6CD5;&#x3001;&#x5DE5;&#x4F5C;&#x6A21;&#x5F0F;&#x3001;&#x586B;&#x5145;&#x65B9;&#x5F0F;
private static final String CIPHER_ALGORITHM = &quot;AES/CBC/PKCS7Padding&quot;;
// &#x5B9A;&#x4E49;&#x81EA;&#x5DF1;&#x7684;&#x79D8;&#x94A5;
public final static String SECRETKEY = &quot;A9e4/vnQTrKF6otAGbM6zGsulKEL7b3x&quot;;
// &#x4F4D;&#x79FB;&#x91CF;
public final static String DISPLACEMENT = &quot;9mg+!7ed8b36*w`X&quot;;

/**
 * &#x83B7;&#x53D6;KEY
 * 
 * @return
 * @throws Exception
 */
private static byte[] getKey() throws Exception {
    return SECRETKEY.getBytes(Charset.forName(&quot;UTF-8&quot;));
}

/**
 * &#x52A0;&#x5BC6;
 * 
 * @param toEncrypt
 *            &#x6587;&#x672C;
 * @return
 * 
 *         &#x52A0;&#x5BC6;&#x8FD4;&#x56DE;&#x6570;&#x7EC4;
 * @throws Exception
 */
@SuppressLint(&quot;TrulyRandom&quot;)
public static byte[] Encrypt(String toEncrypt) throws Exception {
    // &#x79D8;&#x94A5;
    Key secretKey = new SecretKeySpec(getKey(), KEY_ALGORITHM);
    // libs&#x4E2D;bcprov&#x7684;&#x652F;&#x6301;,bouncycastle&#x652F;&#x6301; 64 &#x4F4D;&#x5BC6;&#x94A5;
    Security.addProvider(new BouncyCastleProvider());
    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    // &#x83B7;&#x53D6;&#x4F4D;&#x79FB;&#xFF0C;&#x5E76;&#x521D;&#x59CB;&#x5316;
    final byte[] data = DISPLACEMENT.getBytes();
    IvParameterSpec mIvParameterSpec = new IvParameterSpec(data);
    // &#x7528; iv &#x521D;&#x59CB;&#x5316;
    cipher.init(Cipher.ENCRYPT_MODE, secretKey, mIvParameterSpec);

    final byte[] mEncrypted = cipher.doFinal(toEncrypt.getBytes(Charset
            .forName(&quot;UTF-8&quot;)));

    final byte[] mSpecEncrypted = new byte[data.length + mEncrypted.length];
    System.arraycopy(data, 0, mSpecEncrypted, 0, data.length);
    System.arraycopy(mEncrypted, 0, mSpecEncrypted, data.length,
            mEncrypted.length);
    return mSpecEncrypted;
}

/**
 * &#x52A0;&#x5BC6;&#x6570;&#x636E;
 * 
 * @param encryption
 * 
 *            &#x6587;&#x672C;
 * @return
 * 
 *         &#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;
 * @throws Exception
 */
public static String Encryption(String encryption) throws Exception {
    byte[] entroyResult = Encrypt(encryption);
    String result = new String(Base64.encode(entroyResult, 0), &quot;UTF-8&quot;);
    return result;
}

/**
 * &#x89E3;&#x5BC6;&#x6570;&#x636E;
 * 
 * @param toDecrypt
 *            &#x6587;&#x672C;
 * @return &lt;br&gt;
 *         &#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;
 * @throws Exception
 */
public static String Decrypt(String decrypt) throws Exception {
    byte[] data = Base64.decode(decrypt, 0);
    // &#x79D8;&#x94A5;
    Key secretKey = new SecretKeySpec(getKey(), KEY_ALGORITHM);
    Security.addProvider(new BouncyCastleProvider());
    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    final byte[] mData = DISPLACEMENT.getBytes();
    IvParameterSpec mIvParameterSpec = new IvParameterSpec(mData);
    cipher.init(Cipher.DECRYPT_MODE, secretKey, mIvParameterSpec);
    final byte[] mEncrypted = cipher.doFinal(data);
    // &#x7ED3;&#x679C;
    final byte[] result = new byte[mEncrypted.length - mData.length];
    System.arraycopy(mEncrypted, mData.length, result, 0, result.length);
    return new String(result);
}
}</code></pre><p>##6&#x3001;APP&#x7248;&#x672C;&#x5DE5;&#x5177;&#x7C7B;<br>&#x200B;      public class VersionUtil {</p>
<pre><code>/**
 * &#x83B7;&#x53D6;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x540D;&#x79F0;
 * 
 * @param context
 * @return
 */
public static String getAppName(Context context) {
    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(
                context.getPackageName(), 0);
        int labelRes = packageInfo.applicationInfo.labelRes;
        return context.getResources().getString(labelRes);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

/**
 * &#x83B7;&#x53D6;&#x7248;&#x672C;&#x53F7;
 * 
 * @param context
 * @return &#x5F53;&#x524D;&#x5E94;&#x7528;&#x7684;&#x7248;&#x672C;&#x53F7;
 */
public static String getVersion(Context context) {
    try {
        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(),
                0);
        String version = info.versionName;
        return version;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return &quot;&quot;;
    }
}

/**
 * &#x7248;&#x672C;&#x6BD4;&#x8F83;
 * 
 * @param nowVersion
 *            app&#x7248;&#x672C;
 * @param serverVersion
 *            &#x670D;&#x52A1;&#x5668;&#x7248;&#x672C;
 * @return
 */
public static boolean compareVersion(String nowVersion, String serverVersion) {
    if (nowVersion != null &amp;&amp; serverVersion != null) {
        String[] nowVersions = nowVersion.split(&quot;\\.&quot;);
        String[] serverVersions = serverVersion.split(&quot;\\.&quot;);
        if (nowVersion != null &amp;&amp; serverVersion != null
                &amp;&amp; nowVersions.length &gt; 1 &amp;&amp; serverVersions.length &gt; 1) {
            int nowVersionFirst = Integer.parseInt(nowVersions[0]);
            int serverVersionFirst = Integer.parseInt(serverVersions[0]);
            int nowVersionSecond = Integer.parseInt(nowVersions[1]);
            int serverVersionSecond = Integer.parseInt(serverVersions[1]);
            if (nowVersionFirst &lt; serverVersionFirst) {
                return true;
            } else if (nowVersionFirst == serverVersionFirst
                    &amp;&amp; nowVersionSecond &lt; serverVersionSecond) {
                return true;
            }
        }
    }
    return false;
}
}</code></pre><p>##7&#x3001;GlideUtils<br><strong>&#x8BDD;&#x8BF4;&#x7528;&#x5F00;&#x6E90;&#x5E93;&#x7684;&#x65F6;&#x5019;&#x5E94;&#x8BE5;&#x81EA;&#x884C;&#x5C01;&#x88C5;&#x4E00;&#x4E0B;&#xFF0C;&#x4E3A;&#x4E86;&#x540E;&#x9762;&#x4FEE;&#x6539;&#x65B9;&#x4FBF;&#x3002;</strong><br>&#x200B;      public class GlideUtils {</p>
<pre><code>public GlideUtils(){
    throw new AssertionError();
}

/**
 * &#x663E;&#x793A;&#x7167;&#x7247;
 * @param context
 * @param imageView
 * @param url
 */
public static void displays(Context context, ImageView imageView, Object url) {
    Glide.with(context).load(url).skipMemoryCache(true)  //&#x8DF3;&#x8FC7;&#x5185;&#x5B58;&#x7F13;&#x5B58;
            .diskCacheStrategy(DiskCacheStrategy.ALL) //&#x786C;&#x76D8;&#x7F13;&#x5B58;&#x5168;&#x90E8;
           .into(imageView);
}

/**
 * &#x663E;&#x793A;&#x56FE;&#x7247;
 * @param context
 * @param imageView
 * @param url
 * @param tag
 */
public static void display(Context context, ImageView imageView, String url, Object tag) {
    Glide.with(context).load(url).
            error(R.drawable.ic_error).placeholder(R.drawable.ic_progress).into(imageView);
}

public static void display(Context context, ImageView imageView, String url, int progressId) {
    RequestManager manager = Glide.with(context);
    DrawableTypeRequest&lt;String&gt; load = manager.load(url);
    load.error(R.drawable.ic_error).placeholder(new ColorDrawable(Color.GRAY)).into
            (imageView);
    if (progressId != -1) {
        load.placeholder(progressId);
    }
}

public static void display(Context context, ImageView imageView, String url) {
    display(context, imageView, url, -1);
}

public static void cancel(Context context) {
}
/**
 * &#x8BBE;&#x7F6E;&#x78C1;&#x76D8;&#x7F13;&#x5B58;&#x5927;&#x5C0F;&#x548C;&#x4F4D;&#x7F6E;,&#x8FD9;&#x91CC;&#x8BBE;&#x7F6E;150M
 */
public static void setInnerCacheDir(Context context){
    GlideBuilder builder = new GlideBuilder(context);
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, &quot;ImgCache&quot;, 150 * 1024 * 1024));
}

/**
 * &#x53EF;&#x4EE5;&#x7528;ExternalCacheDiskCacheFactory&#x6765;&#x628A;&#x4F60;&#x7684;&#x78C1;&#x76D8;&#x7F13;&#x5B58;&#x653E;&#x5230;sd&#x5361;&#x7684;&#x516C;&#x5171;&#x7F13;&#x5B58;&#x76EE;&#x5F55;&#x4E0A;,&#x8FD9;&#x91CC;&#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;150M
 */
public static void setDiskCacheDir(Context context){
    GlideBuilder builder = new GlideBuilder(context);
    builder.setDiskCache( new ExternalCacheDiskCacheFactory(context, &quot;ImgCache&quot;, 150 * 1024 * 1024));
}

/**
 * &#x6E05;&#x9664;&#x7F13;&#x5B58;
 */
public static  void clearCache(final Context context){
    Glide.get(context).clearMemory(); //&#x6E05;&#x7406;&#x5185;&#x5B58;&#x7F13;&#x5B58;
    new Thread(new Runnable() {
        @Override
        public void run() {
            Glide.get(context).clearDiskCache(); //&#x6E05;&#x7406;&#x78C1;&#x76D8;&#x7F13;&#x5B58;
        }
    }).start();
}
}</code></pre><p>##8&#x3001;&#x7F13;&#x5B58;&#x5DE5;&#x5177;&#x7C7B;<br>&#x200B;      public class CacheUtil {</p>
<pre><code>public CacheUtil() {
    throw new UnsupportedOperationException(&quot;cannot be instantiated&quot;);
}

/**
 * &#x5F97;&#x5230;&#x7F13;&#x5B58;&#x5927;&#x5C0F;
 *
 * @param context &#x4E0A;&#x4E0B;&#x6587;
 * @return
 * @throws IOException
 */
public static String getTotalCacheSize(Context context) throws IOException {
    //&#x7F13;&#x5B58;&#x5927;&#x5C0F;
    long cacheSize = getFolderSize(context.getCacheDir());
    // &#x5982;&#x679C;SD&#x5361;&#x6B63;&#x5E38;&#x6302;&#x8F7D;&#x624D;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x6587;&#x4EF6;&#x6216;&#x8005;&#x5199;&#x5165;&#x6587;&#x4EF6;&#x7B49;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        cacheSize += getFolderSize(context.getCacheDir());
    }
     return  getFormatSize(cacheSize);
}

/**
 * &#x5F97;&#x5230;&#x4E34;&#x65F6;&#x7F13;&#x5B58;&#x6570;&#x636E;
 *
 * @param file
 * @return
 * @throws IOException
 */
public static long getFolderSize(File file) throws IOException {
    long size = 0;
    //&#x6587;&#x4EF6;
    File[] fileList = file.listFiles();
    for (int i = 0; i &lt; fileList.length; i++) {
        if (fileList[i].isDirectory()) {
            size = size + getFolderSize(fileList[i]);
        } else {
            size = size + fileList[i].length();
        }
    }
    return size;
}

/**
 * &#x6E05;&#x9664;&#x6240;&#x6709;&#x7F13;&#x5B58;
 */
public static void clearAllCache(Context context) {
    //&#x5220;&#x9664;&#x7F13;&#x5B58;
    deleteDir(context.getCacheDir());
    //&#x5982;&#x679C;&#x5B58;&#x5728;SD&#x5361;&#x5219;&#x5220;&#x9664;&#x672C;&#x5730;&#x7F13;&#x5B58;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        deleteDir(context.getExternalCacheDir());
    }

}

/**
 * &#x662F;&#x5426;&#x5220;&#x9664;&#x6587;&#x4EF6;
 *
 * @return
 */
public static boolean deleteDir(File dir) {
    // &#x6587;&#x4EF6;&#x4E0D;&#x4E3A;&#x7A7A;&#x5E76;&#x4E14;&#x662F;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x5939;&#x65F6;
    if (dir != null &amp;&amp; dir.isDirectory()) {
        //&#x5F97;&#x5230;&#x6587;&#x4EF6;&#x96C6;&#x5408;
        String[] child = dir.list();
        for (int i = 0; i &lt; child.length; i++) {
            //&#x662F;&#x5426;&#x5220;&#x9664;&#x6210;&#x529F;
            boolean isSuccess = deleteDir(new File(dir, child[i]));
            if (!isSuccess) {
                return false;
            }
        }
    }
    return dir.delete();
}

/**
 * &#x683C;&#x5F0F;&#x5316;
 *
 * @return
 */
public static String getFormatSize(double size) {
    //KB
    double kiloByte = size / 1024;
    if (kiloByte&lt;1){
        return size+&quot;Byte&quot;;
    }
    //MB
    double megaByte=kiloByte/1024;
    if (megaByte&lt;1){
        //&#x9AD8;&#x7CBE;&#x5EA6;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;
        BigDecimal result1=new BigDecimal(Double.toString(kiloByte));
        //&#x56DB;&#x820D;&#x4E94;&#x5165;
        return result1.setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString()+&quot;KB&quot;;
    }
    //GB
    double gigaByte = megaByte/1024;
    if (gigaByte&lt;1){
        BigDecimal result2= new BigDecimal(Double.toString(megaByte));
        return  result2.setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString()+&quot;MB&quot;;
    }
    //TB
    double teraByte =gigaByte/1024;
    if (teraByte&lt;1){
        BigDecimal result3= new BigDecimal(Double.toString(gigaByte));
        return  result3.setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString()+&quot;GB&quot;;
    }
    BigDecimal result4= new BigDecimal(teraByte);
    return result4.setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString()+&quot;TB&quot;;
}
}</code></pre><p>##9&#x3001;SharedPreferences&#x5C01;&#x88C5;&#x7C7B;<br>&#x200B;      public class SPUtils {<br>&#x200B;    /**<br>&#x200B;     * &#x4FDD;&#x5B58;&#x5728;&#x624B;&#x673A;&#x91CC;&#x9762;&#x7684;&#x6587;&#x4EF6;&#x540D;<br>&#x200B;     */<br>&#x200B;    public static final String FILE_NAME = &#x201C;share_data&#x201D;;</p>
<pre><code>/**
 * &#x4FDD;&#x5B58;&#x6570;&#x636E;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x62FF;&#x5230;&#x4FDD;&#x5B58;&#x6570;&#x636E;&#x7684;&#x5177;&#x4F53;&#x7C7B;&#x578B;&#xFF0C;&#x7136;&#x540E;&#x6839;&#x636E;&#x7C7B;&#x578B;&#x8C03;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x4FDD;&#x5B58;&#x65B9;&#x6CD5;
 * 
 * @param context
 * @param key
 * @param object
 */
public static void put(Context context, String key, Object object) {

    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();

    if (object instanceof String) {
        editor.putString(key, (String) object);
    } else if (object instanceof Integer) {
        editor.putInt(key, (Integer) object);
    } else if (object instanceof Boolean) {
        editor.putBoolean(key, (Boolean) object);
    } else if (object instanceof Float) {
        editor.putFloat(key, (Float) object);
    } else if (object instanceof Long) {
        editor.putLong(key, (Long) object);
    } else {
        editor.putString(key, object.toString());
    }

    /**
     * commit&#x64CD;&#x4F5C;&#x4F7F;&#x7528;&#x4E86;SharedPreferencesCompat.apply&#x8FDB;&#x884C;&#x4E86;&#x66FF;&#x4EE3;&#xFF0C;&#x76EE;&#x7684;&#x662F;&#x5C3D;&#x53EF;&#x80FD;&#x7684;&#x4F7F;&#x7528;apply&#x4EE3;&#x66FF;commit
     * &#x56E0;&#x4E3A;commit&#x65B9;&#x6CD5;&#x662F;&#x540C;&#x6B65;&#x7684;&#xFF0C;&#x5E76;&#x4E14;&#x6211;&#x4EEC;&#x5F88;&#x591A;&#x65F6;&#x5019;&#x7684;commit&#x64CD;&#x4F5C;&#x90FD;&#x662F;UI&#x7EBF;&#x7A0B;&#x4E2D;&#xFF0C;&#x6BD5;&#x7ADF;&#x662F;IO&#x64CD;&#x4F5C;&#xFF0C;&#x5C3D;&#x53EF;&#x80FD;&#x5F02;&#x6B65;&#xFF1B;
     */
    SharedPreferencesCompat.apply(editor);
}

/**
 * &#x5F97;&#x5230;&#x4FDD;&#x5B58;&#x6570;&#x636E;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x6839;&#x636E;&#x9ED8;&#x8BA4;&#x503C;&#x5F97;&#x5230;&#x4FDD;&#x5B58;&#x7684;&#x6570;&#x636E;&#x7684;&#x5177;&#x4F53;&#x7C7B;&#x578B;&#xFF0C;&#x7136;&#x540E;&#x8C03;&#x7528;&#x76F8;&#x5BF9;&#x4E8E;&#x7684;&#x65B9;&#x6CD5;&#x83B7;&#x53D6;&#x503C;
 * 
 * @param context
 * @param key
 * @param defaultObject
 * @return
 */
public static Object get(Context context, String key, Object defaultObject) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);

    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    }

    return null;
}

/**
 * &#x79FB;&#x9664;&#x67D0;&#x4E2A;key&#x503C;&#x5DF2;&#x7ECF;&#x5BF9;&#x5E94;&#x7684;&#x503C;
 * 
 * @param context
 * @param key
 */
public static void remove(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.remove(key);
    SharedPreferencesCompat.apply(editor);
}

/**
 * &#x6E05;&#x9664;&#x6240;&#x6709;&#x6570;&#x636E;
 * 
 * @param context
 */
public static void clear(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.clear();
    SharedPreferencesCompat.apply(editor);
}

/**
 * &#x67E5;&#x8BE2;&#x67D0;&#x4E2A;key&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;
 * 
 * @param context
 * @param key
 * @return
 */
public static boolean contains(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);
    return sp.contains(key);
}

/**
 * &#x8FD4;&#x56DE;&#x6240;&#x6709;&#x7684;&#x952E;&#x503C;&#x5BF9;
 * 
 * @param context
 * @return
 */
public static Map&lt;String, ?&gt; getAll(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);
    return sp.getAll();
}

/**
 * &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x89E3;&#x51B3;SharedPreferencesCompat.apply&#x65B9;&#x6CD5;&#x7684;&#x4E00;&#x4E2A;&#x517C;&#x5BB9;&#x7C7B;
 * 
 * @author dj
 */
private static class SharedPreferencesCompat {
    private static final Method sApplyMethod = findApplyMethod();

    /**
     * &#x53CD;&#x5C04;&#x67E5;&#x627E;apply&#x7684;&#x65B9;&#x6CD5;
     * 
     * @return
     */
    @SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })
    private static Method findApplyMethod() {
        try {
            Class clz = SharedPreferences.Editor.class;
            return clz.getMethod(&quot;apply&quot;);
        } catch (NoSuchMethodException e) {
        }

        return null;
    }

    /**
     * &#x5982;&#x679C;&#x627E;&#x5230;&#x5219;&#x4F7F;&#x7528;apply&#x6267;&#x884C;&#xFF0C;&#x5426;&#x5219;&#x4F7F;&#x7528;commit
     * 
     * @param editor
     */
    public static void apply(SharedPreferences.Editor editor) {
        try {
            if (sApplyMethod != null) {
                sApplyMethod.invoke(editor);
                return;
            }
        } catch (IllegalArgumentException e) {
        } catch (IllegalAccessException e) {
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        editor.commit();
    }
}
}</code></pre><p>##10&#x3001;&#x624B;&#x673A;&#x4FE1;&#x606F;&#x91C7;&#x96C6;&#x5DE5;&#x5177;&#x7C7B;<br>&#x200B;      public class MobileUtil {</p>
<pre><code>/**
 * Print telephone info.
 */
public static String printMobileInfo(Context context) {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat dateFormat = new SimpleDateFormat(
            &quot;yyyy-MM-dd HH:mm:ss&quot;);
    String time = dateFormat.format(date);
    StringBuilder sb = new StringBuilder();
    sb.append(&quot;&#x7CFB;&#x7EDF;&#x65F6;&#x95F4;&#xFF1A;&quot;).append(time).append(&quot;\n&quot;);
    TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = tm.getSubscriberId();
    // IMSI&#x524D;&#x9762;&#x4E09;&#x4F4D;460&#x662F;&#x56FD;&#x5BB6;&#x53F7;&#x7801;&#xFF0C;&#x5176;&#x6B21;&#x7684;&#x4E24;&#x4F4D;&#x662F;&#x8FD0;&#x8425;&#x5546;&#x4EE3;&#x53F7;&#xFF0C;00&#x3001;02&#x662F;&#x4E2D;&#x56FD;&#x79FB;&#x52A8;&#xFF0C;01&#x662F;&#x8054;&#x901A;&#xFF0C;03&#x662F;&#x7535;&#x4FE1;&#x3002;
    String providerName = null;
    if (IMSI != null) {
        if (IMSI.startsWith(&quot;46000&quot;) || IMSI.startsWith(&quot;46002&quot;)) {
            providerName = &quot;&#x4E2D;&#x56FD;&#x79FB;&#x52A8;&quot;;
        } else if (IMSI.startsWith(&quot;46001&quot;)) {
            providerName = &quot;&#x4E2D;&#x56FD;&#x8054;&#x901A;&quot;;
        } else if (IMSI.startsWith(&quot;46003&quot;)) {
            providerName = &quot;&#x4E2D;&#x56FD;&#x7535;&#x4FE1;&quot;;
        }
    }
    sb.append(providerName).append(&quot;\n&quot;)
            .append(getNativePhoneNumber(context)).append(&quot;\n&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;&#xFF1A;&quot;)
            .append(getNetType(context)).append(&quot;\nIMSI&#x662F;&#xFF1A;&quot;).append(IMSI);
    sb.append(&quot;\nDeviceID(IMEI)       :&quot;).append(tm.getDeviceId());
    sb.append(&quot;\nDeviceSoftwareVersion:&quot;).append(
            tm.getDeviceSoftwareVersion());
    sb.append(&quot;\ngetLine1Number       :&quot;).append(tm.getLine1Number());
    sb.append(&quot;\nNetworkCountryIso    :&quot;).append(tm.getNetworkCountryIso());
    sb.append(&quot;\nNetworkOperator      :&quot;).append(tm.getNetworkOperator());
    sb.append(&quot;\nNetworkOperatorName  :&quot;).append(
            tm.getNetworkOperatorName());
    sb.append(&quot;\nNetworkType          :&quot;).append(tm.getNetworkType());
    sb.append(&quot;\nPhoneType            :&quot;).append(tm.getPhoneType());
    sb.append(&quot;\nSimCountryIso        :&quot;).append(tm.getSimCountryIso());
    sb.append(&quot;\nSimOperator          :&quot;).append(tm.getSimOperator());
    sb.append(&quot;\nSimOperatorName      :&quot;).append(tm.getSimOperatorName());
    sb.append(&quot;\nSimSerialNumber      :&quot;).append(tm.getSimSerialNumber());
    sb.append(&quot;\ngetSimState          :&quot;).append(tm.getSimState());
    sb.append(&quot;\nSubscriberId         :&quot;).append(tm.getSubscriberId());
    sb.append(&quot;\nVoiceMailNumber      :&quot;).append(tm.getVoiceMailNumber());

    return sb.toString();
}

/**
 * &#x6253;&#x5370;&#x7CFB;&#x7EDF;&#x4FE1;&#x606F;
 * 
 * @return
 */
public static String printSystemInfo() {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat dateFormat = new SimpleDateFormat(
            &quot;yyyy-MM-dd HH:mm:ss&quot;);
    String time = dateFormat.format(date);
    StringBuilder sb = new StringBuilder();
    sb.append(&quot;_______  &#x7CFB;&#x7EDF;&#x4FE1;&#x606F;  &quot;).append(time).append(&quot; ______________&quot;);
    sb.append(&quot;\nID                 :&quot;).append(Build.ID);
    sb.append(&quot;\nBRAND              :&quot;).append(Build.BRAND);
    sb.append(&quot;\nMODEL              :&quot;).append(Build.MODEL);
    sb.append(&quot;\nRELEASE            :&quot;).append(Build.VERSION.RELEASE);
    sb.append(&quot;\nSDK                :&quot;).append(Build.VERSION.SDK);

    sb.append(&quot;\n_______ OTHER _______&quot;);
    sb.append(&quot;\nBOARD              :&quot;).append(Build.BOARD);
    sb.append(&quot;\nPRODUCT            :&quot;).append(Build.PRODUCT);
    sb.append(&quot;\nDEVICE             :&quot;).append(Build.DEVICE);
    sb.append(&quot;\nFINGERPRINT        :&quot;).append(Build.FINGERPRINT);
    sb.append(&quot;\nHOST               :&quot;).append(Build.HOST);
    sb.append(&quot;\nTAGS               :&quot;).append(Build.TAGS);
    sb.append(&quot;\nTYPE               :&quot;).append(Build.TYPE);
    sb.append(&quot;\nTIME               :&quot;).append(Build.TIME);
    sb.append(&quot;\nINCREMENTAL        :&quot;).append(Build.VERSION.INCREMENTAL);

    sb.append(&quot;\n_______ CUPCAKE-3 _______&quot;);
    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.CUPCAKE) {
        sb.append(&quot;\nDISPLAY            :&quot;).append(Build.DISPLAY);
    }

    sb.append(&quot;\n_______ DONUT-4 _______&quot;);
    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.DONUT) {
        sb.append(&quot;\nSDK_INT            :&quot;).append(Build.VERSION.SDK_INT);
        sb.append(&quot;\nMANUFACTURER       :&quot;).append(Build.MANUFACTURER);
        sb.append(&quot;\nBOOTLOADER         :&quot;).append(Build.BOOTLOADER);
        sb.append(&quot;\nCPU_ABI            :&quot;).append(Build.CPU_ABI);
        sb.append(&quot;\nCPU_ABI2           :&quot;).append(Build.CPU_ABI2);
        sb.append(&quot;\nHARDWARE           :&quot;).append(Build.HARDWARE);
        sb.append(&quot;\nUNKNOWN            :&quot;).append(Build.UNKNOWN);
        sb.append(&quot;\nCODENAME           :&quot;).append(Build.VERSION.CODENAME);
    }

    sb.append(&quot;\n_______ GINGERBREAD-9 _______&quot;);
    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.GINGERBREAD) {
        sb.append(&quot;\nSERIAL             :&quot;).append(Build.SERIAL);
    }
    return sb.toString();
}

/****
 * &#x83B7;&#x53D6;&#x7F51;&#x7EDC;&#x7C7B;&#x578B;
 * 
 * @param context
 * @return
 */
public static String getNetType(Context context) {
    try {
        ConnectivityManager connectMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = connectMgr.getActiveNetworkInfo();
        if (info == null) {
            return &quot;&quot;;
        }
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            return &quot;WIFI&quot;;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_CDMA) {
                return &quot;CDMA&quot;;
            } else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EDGE) {
                return &quot;EDGE&quot;;
            } else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EVDO_0) {
                return &quot;EVDO0&quot;;
            } else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_EVDO_A) {
                return &quot;EVDOA&quot;;
            } else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_GPRS) {
                return &quot;GPRS&quot;;
            }
            /*
             * else if(info.getSubtype() ==
             * TelephonyManager.NETWORK_TYPE_HSDPA){ return &quot;HSDPA&quot;; }else
             * if(info.getSubtype() == TelephonyManager.NETWORK_TYPE_HSPA){
             * return &quot;HSPA&quot;; }else if(info.getSubtype() ==
             * TelephonyManager.NETWORK_TYPE_HSUPA){ return &quot;HSUPA&quot;; }
             */
            else if (info.getSubtype() == TelephonyManager.NETWORK_TYPE_UMTS) {
                return &quot;UMTS&quot;;
            } else {
                return &quot;3G&quot;;
            }
        } else {
            return &quot;&quot;;
        }
    } catch (Exception e) {
        return &quot;&quot;;
    }
}

/**
 * &#x83B7;&#x53D6;&#x5F53;&#x524D;&#x8BBE;&#x7F6E;&#x7684;&#x7535;&#x8BDD;&#x53F7;&#x7801;
 */
public static String getNativePhoneNumber(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String NativePhoneNumber = null;
    NativePhoneNumber = telephonyManager.getLine1Number();
    return String.format(&quot;&#x624B;&#x673A;&#x53F7;: %s&quot;, NativePhoneNumber);
}

/**
 * IMSI&#x662F;&#x56FD;&#x9645;&#x79FB;&#x52A8;&#x7528;&#x6237;&#x8BC6;&#x522B;&#x7801;&#x7684;&#x7B80;&#x79F0;(International Mobile Subscriber Identity)
 * IMSI&#x5171;&#x6709;15&#x4F4D;&#xFF0C;&#x5176;&#x7ED3;&#x6784;&#x5982;&#x4E0B;&#xFF1A; &lt;br&gt;
 * MCC+MNC+MIN &lt;br&gt;
 * MCC&#xFF1A;Mobile Country Code&#xFF0C;&#x79FB;&#x52A8;&#x56FD;&#x5BB6;&#x7801;&#xFF0C;&#x5171;3&#x4F4D;&#xFF0C;&#x4E2D;&#x56FD;&#x4E3A;460;&lt;br&gt;
 * MNC:Mobile NetworkCode&#xFF0C;&#x79FB;&#x52A8;&#x7F51;&#x7EDC;&#x7801;&#xFF0C;&#x5171;2&#x4F4D; &lt;br&gt;
 * &#x5728;&#x4E2D;&#x56FD;&#xFF0C;&#x79FB;&#x52A8;&#x7684;&#x4EE3;&#x7801;&#x4E3A;&#x7535;00&#x548C;02&#xFF0C;&#x8054;&#x901A;&#x7684;&#x4EE3;&#x7801;&#x4E3A;01&#xFF0C;&#x7535;&#x4FE1;&#x7684;&#x4EE3;&#x7801;&#x4E3A;03&lt;br&gt;
 * &#x5408;&#x8D77;&#x6765;&#x5C31;&#x662F;&#xFF08;&#x4E5F;&#x662F;Android&#x624B;&#x673A;&#x4E2D;APN&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#xFF09;&#xFF1A; &lt;br&gt;
 * &#x4E2D;&#x56FD;&#x79FB;&#x52A8;&#xFF1A;46000 46002 &lt;br&gt;
 * &#x4E2D;&#x56FD;&#x8054;&#x901A;&#xFF1A;46001 &lt;br&gt;
 * &#x4E2D;&#x56FD;&#x7535;&#x4FE1;&#xFF1A;46003 &lt;br&gt;
 * &#x4E3E;&#x4F8B;&#xFF0C;&#x4E00;&#x4E2A;&#x5178;&#x578B;&#x7684;IMSI&#x53F7;&#x7801;&#x4E3A;460030912121001 &lt;br&gt;
 */
public static String getIMSI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String IMSI = telephonyManager.getSubscriberId();
    return IMSI;
}

/**
 * IMEI&#x662F;International Mobile Equipment Identity &#xFF08;&#x56FD;&#x9645;&#x79FB;&#x52A8;&#x8BBE;&#x5907;&#x6807;&#x8BC6;&#xFF09;&#x7684;&#x7B80;&#x79F0;
 * IMEI&#x7531;15&#x4F4D;&#x6570;&#x5B57;&#x7EC4;&#x6210;&#x7684;&#x201D;&#x7535;&#x5B50;&#x4E32;&#x53F7;&#x201D;&#xFF0C;&#x5B83;&#x4E0E;&#x6BCF;&#x53F0;&#x624B;&#x673A;&#x4E00;&#x4E00;&#x5BF9;&#x5E94;&#xFF0C;&#x800C;&#x4E14;&#x8BE5;&#x7801;&#x662F;&#x5168;&#x4E16;&#x754C;&#x552F;&#x4E00;&#x7684; &#x5176;&#x7EC4;&#x6210;&#x4E3A;&#xFF1A;
 * 1.&#x524D;6&#x4F4D;&#x6570;(TAC)&#x662F;&#x201D;&#x578B;&#x53F7;&#x6838;&#x51C6;&#x53F7;&#x7801;&#x201D;&#xFF0C;&#x4E00;&#x822C;&#x4EE3;&#x8868;&#x673A;&#x578B; &lt;br&gt;
 * 2. &#x63A5;&#x7740;&#x7684;2&#x4F4D;&#x6570;(FAC)&#x662F;&#x201D;&#x6700;&#x540E;&#x88C5;&#x914D;&#x53F7;&#x201D;&#xFF0C;&#x4E00;&#x822C;&#x4EE3;&#x8868;&#x4EA7;&#x5730; &lt;br&gt;
 * 3.&#x4E4B;&#x540E;&#x7684;6&#x4F4D;&#x6570;(SNR)&#x662F;&#x201D;&#x4E32;&#x53F7;&#x201D;&#xFF0C;&#x4E00;&#x822C;&#x4EE3;&#x8868;&#x751F;&#x4EA7;&#x987A;&#x5E8F;&#x53F7; &lt;br&gt;
 * 4. &#x6700;&#x540E;1&#x4F4D;&#x6570;(SP)&#x901A;&#x5E38;&#x662F;&#x201D;0&#x2033;&#xFF0C;&#x4E3A;&#x68C0;&#x9A8C;&#x7801;&#xFF0C;&#x76EE;&#x524D;&#x6682;&#x5907;&#x7528;&lt;br&gt;
 */
public static String getIMEI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    String IMEI = telephonyManager.getDeviceId();
    return IMEI;
}

// ///_________________ &#x53CC;&#x5361;&#x53CC;&#x5F85;&#x7CFB;&#x7EDF;IMEI&#x548C;IMSI&#x65B9;&#x6848;&#xFF08;see more on
// http://benson37.iteye.com/blog/1923946&#xFF09;

/**
 * &#x53CC;&#x5361;&#x53CC;&#x5F85;&#x795E;&#x673A;IMSI&#x3001;IMSI&#x3001;PhoneType&#x4FE1;&#x606F; &lt;uses-permission
 * android:name=&quot;android.permission.READ_PHONE_STATE&quot;/&gt;
 */
public static class TeleInfo {
    public String imsi_1;
    public String imsi_2;
    public String imei_1;
    public String imei_2;
    public int phoneType_1;
    public int phoneType_2;

    @Override
    public String toString() {
        return &quot;TeleInfo{&quot; + &quot;imsi_1=&apos;&quot; + imsi_1 + &apos;\&apos;&apos; + &quot;, imsi_2=&apos;&quot;
                + imsi_2 + &apos;\&apos;&apos; + &quot;, imei_1=&apos;&quot; + imei_1 + &apos;\&apos;&apos;
                + &quot;, imei_2=&apos;&quot; + imei_2 + &apos;\&apos;&apos; + &quot;, phoneType_1=&quot;
                + phoneType_1 + &quot;, phoneType_2=&quot; + phoneType_2 + &apos;}&apos;;
    }
}

/**
 * MTK Phone.
 * &lt;p&gt;
 * &#x83B7;&#x53D6; MTK &#x795E;&#x673A;&#x7684;&#x53CC;&#x5361; IMSI&#x3001;IMSI &#x4FE1;&#x606F;
 */
public static TeleInfo getMtkTeleInfo(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {
        Class&lt;?&gt; phone = Class
                .forName(&quot;com.android.internal.telephony.Phone&quot;);

        Field fields1 = phone.getField(&quot;GEMINI_SIM_1&quot;);
        fields1.setAccessible(true);
        int simId_1 = (Integer) fields1.get(null);

        Field fields2 = phone.getField(&quot;GEMINI_SIM_2&quot;);
        fields2.setAccessible(true);
        int simId_2 = (Integer) fields2.get(null);

        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        Method getSubscriberIdGemini = TelephonyManager.class
                .getDeclaredMethod(&quot;getSubscriberIdGemini&quot;, int.class);
        String imsi_1 = (String) getSubscriberIdGemini.invoke(tm, simId_1);
        String imsi_2 = (String) getSubscriberIdGemini.invoke(tm, simId_2);
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        Method getDeviceIdGemini = TelephonyManager.class
                .getDeclaredMethod(&quot;getDeviceIdGemini&quot;, int.class);
        String imei_1 = (String) getDeviceIdGemini.invoke(tm, simId_1);
        String imei_2 = (String) getDeviceIdGemini.invoke(tm, simId_2);

        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        Method getPhoneTypeGemini = TelephonyManager.class
                .getDeclaredMethod(&quot;getPhoneTypeGemini&quot;, int.class);
        int phoneType_1 = (Integer) getPhoneTypeGemini.invoke(tm, simId_1);
        int phoneType_2 = (Integer) getPhoneTypeGemini.invoke(tm, simId_2);
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return teleInfo;
}

/**
 * MTK Phone.
 * &lt;p&gt;
 * &#x83B7;&#x53D6; MTK &#x795E;&#x673A;&#x7684;&#x53CC;&#x5361; IMSI&#x3001;IMSI &#x4FE1;&#x606F;
 */
public static TeleInfo getMtkTeleInfo2(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        Class&lt;?&gt; phone = Class
                .forName(&quot;com.android.internal.telephony.Phone&quot;);
        Field fields1 = phone.getField(&quot;GEMINI_SIM_1&quot;);
        fields1.setAccessible(true);
        int simId_1 = (Integer) fields1.get(null);
        Field fields2 = phone.getField(&quot;GEMINI_SIM_2&quot;);
        fields2.setAccessible(true);
        int simId_2 = (Integer) fields2.get(null);

        Method getDefault = TelephonyManager.class.getMethod(&quot;getDefault&quot;,
                int.class);
        TelephonyManager tm1 = (TelephonyManager) getDefault.invoke(tm,
                simId_1);
        TelephonyManager tm2 = (TelephonyManager) getDefault.invoke(tm,
                simId_2);

        String imsi_1 = tm1.getSubscriberId();
        String imsi_2 = tm2.getSubscriberId();
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        String imei_1 = tm1.getDeviceId();
        String imei_2 = tm2.getDeviceId();
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        int phoneType_1 = tm1.getPhoneType();
        int phoneType_2 = tm2.getPhoneType();
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return teleInfo;
}

/**
 * Qualcomm Phone. &#x83B7;&#x53D6; &#x9AD8;&#x901A; &#x795E;&#x673A;&#x7684;&#x53CC;&#x5361; IMSI&#x3001;IMSI &#x4FE1;&#x606F;
 */
public static TeleInfo getQualcommTeleInfo(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        Class&lt;?&gt; simTMclass = Class
                .forName(&quot;android.telephony.MSimTelephonyManager&quot;);
        // Object sim = context.getSystemService(&quot;phone_msim&quot;);
        Object sim = context.getSystemService(Context.TELEPHONY_SERVICE);
        int simId_1 = 0;
        int simId_2 = 1;

        Method getSubscriberId = simTMclass.getMethod(&quot;getSubscriberId&quot;,
                int.class);
        String imsi_1 = (String) getSubscriberId.invoke(sim, simId_1);
        String imsi_2 = (String) getSubscriberId.invoke(sim, simId_2);
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        Method getDeviceId = simTMclass.getMethod(&quot;getDeviceId&quot;, int.class);
        String imei_1 = (String) getDeviceId.invoke(sim, simId_1);
        String imei_2 = (String) getDeviceId.invoke(sim, simId_2);
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        Method getDataState = simTMclass.getMethod(&quot;getDataState&quot;);
        int phoneType_1 = tm.getDataState();
        int phoneType_2 = (Integer) getDataState.invoke(sim);
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return teleInfo;
}

/**
 * Spreadtrum Phone.
 * &lt;p&gt;
 * &#x83B7;&#x53D6; &#x5C55;&#x8BAF; &#x795E;&#x673A;&#x7684;&#x53CC;&#x5361; IMSI&#x3001;IMSI &#x4FE1;&#x606F;
 */
public static TeleInfo getSpreadtrumTeleInfo(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {

        TelephonyManager tm1 = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        String imsi_1 = tm1.getSubscriberId();
        String imei_1 = tm1.getDeviceId();
        int phoneType_1 = tm1.getPhoneType();
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imei_1 = imei_1;
        teleInfo.phoneType_1 = phoneType_1;

        Class&lt;?&gt; phoneFactory = Class
                .forName(&quot;com.android.internal.telephony.PhoneFactory&quot;);
        Method getServiceName = phoneFactory.getMethod(&quot;getServiceName&quot;,
                String.class, int.class);
        getServiceName.setAccessible(true);
        TelephonyManager tm2 = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        String imsi_2 = tm2.getSubscriberId();
        String imei_2 = tm2.getDeviceId();
        int phoneType_2 = tm2.getPhoneType();
        teleInfo.imsi_2 = imsi_2;
        teleInfo.imei_2 = imei_2;
        teleInfo.phoneType_2 = phoneType_2;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return teleInfo;
}

/**
 * &#x83B7;&#x53D6; MAC &#x5730;&#x5740; &lt;uses-permission
 * android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot;/&gt;
 */
public static String getMacAddress(Context context) {
    // wifi mac&#x5730;&#x5740;
    WifiManager wifi = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    String mac = info.getMacAddress();

    return mac;
}

/**
 * &#x83B7;&#x53D6; &#x5F00;&#x673A;&#x65F6;&#x95F4;
 */
public static String getBootTimeString() {
    long ut = SystemClock.elapsedRealtime() / 1000;
    int h = (int) ((ut / 3600));
    int m = (int) ((ut / 60) % 60);

    return h + &quot;:&quot; + m;
}
}</code></pre><p>##11&#x3001;CommonUtils<br>&#x200B;      public class CommonUtils {<br>&#x200B;<br>&#x200B;    static Context context;<br>&#x200B;    // &#x624B;&#x673A;&#x7F51;&#x7EDC;&#x7C7B;&#x578B;<br>&#x200B;    public static final int NETTYPE_WIFI = 0x01;<br>&#x200B;    public static final int NETTYPE_CMWAP = 0x02;<br>&#x200B;    public static final int NETTYPE_CMNET = 0x03;<br>&#x200B;<br>&#x200B;    public static boolean GTE_HC;<br>&#x200B;    public static boolean GTE_ICS;<br>&#x200B;    public static boolean PRE_HC;<br>&#x200B;    private static Boolean _hasBigScreen = null;<br>&#x200B;    private static Boolean _hasCamera = null;<br>&#x200B;    private static Boolean _isTablet = null;<br>&#x200B;    private static Integer _loadFactor = null;<br>&#x200B;<br>&#x200B;    private static int _pageSize = -1;<br>&#x200B;    public static float displayDensity = 0.0F;<br>&#x200B;    public static final String TAG = context.getClass().getSimpleName();<br>&#x200B;<br>&#x200B;    static {<br>&#x200B;        GTE_ICS = Build.VERSION.SDK_INT &gt;= 14;<br>&#x200B;        GTE_HC = Build.VERSION.SDK_INT &gt;= 11;<br>&#x200B;        PRE_HC = Build.VERSION.SDK_INT &gt;= 11 ? false : true;<br>&#x200B;    }<br>&#x200B;<br>    public CommonUtils() {<br>        throw new AssertionError();<br>    }</p>
<pre><code>/**
 * &#x83B7;&#x53D6;&#x7CFB;&#x7EDF;&#x5F53;&#x524D;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x6233;
 */

public static String getTimesTamp() {
    long timestamp = System.currentTimeMillis() / 1000;
    return String.valueOf(timestamp);
}

public static int[] getRealScreenSize(Activity activity) {
    int[] size = new int[2];
    int screenWidth = 0, screenHeight = 0;
    WindowManager w = activity.getWindowManager();
    Display d = w.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);
    // since SDK_INT = 1;
    screenWidth = metrics.widthPixels;
    screenHeight = metrics.heightPixels;
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT &gt;= 14 &amp;&amp; Build.VERSION.SDK_INT &lt; 17)
        try {
            screenWidth = (Integer) Display.class.getMethod(&quot;getRawWidth&quot;)
                    .invoke(d);
            screenHeight = (Integer) Display.class
                    .getMethod(&quot;getRawHeight&quot;).invoke(d);
        } catch (Exception ignored) {
        }
    // includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT &gt;= 17)
        try {
            Point realSize = new Point();
            Display.class.getMethod(&quot;getRealSize&quot;, Point.class).invoke(d,
                    realSize);
            screenWidth = realSize.x;
            screenHeight = realSize.y;
        } catch (Exception ignored) {
        }
    size[0] = screenWidth;
    size[1] = screenHeight;
    return size;
}

/**
 * &#x662F;&#x5426;&#x5B58;&#x5728;&#x76F8;&#x673A;
 * 
 * @return
 */
public static final boolean hasCamera(Context context) {
    if (_hasCamera == null) {
        PackageManager pckMgr = context.getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature(&quot;android.hardware.camera.front&quot;);
        boolean flag1 = pckMgr.hasSystemFeature(&quot;android.hardware.camera&quot;);
        boolean flag2;
        if (flag || flag1)
            flag2 = true;
        else
            flag2 = false;
        _hasCamera = Boolean.valueOf(flag2);
    }
    return _hasCamera.booleanValue();
}

/**
 * &#x5224;&#x65AD;&#x662F;&#x5426;&#x6709;&#x7269;&#x7406;&#x7684;menu&#x952E;
 * 
 * @param context
 * @return
 */
public static boolean hasHardwareMenuKey(Context context) {
    boolean flag = false;
    if (PRE_HC)
        flag = true;
    else if (GTE_ICS) {
        flag = ViewConfiguration.get(context).hasPermanentMenuKey();
    } else
        flag = false;
    return flag;
}

/**
 * &#x662F;&#x5426;&#x6709;google&#x5546;&#x5E97;
 * 
 * @param activity
 * @param pck
 * @return
 */
public static boolean gotoGoogleMarket(Activity activity, String pck) {
    try {
        Intent intent = new Intent();
        intent.setPackage(&quot;com.android.vending&quot;);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(&quot;market://details?id=&quot; + pck));
        activity.startActivity(intent);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

/**
 * &#x9690;&#x85CF;&#x52A8;&#x753B;&#x89C6;&#x56FE;
 * 
 * @param view
 */
public static void hideAnimatedView(View view) {
    if (PRE_HC &amp;&amp; view != null)
        view.setPadding(view.getWidth(), 0, 0, 0);
}

/**
 * &#x663E;&#x793A;&#x52A8;&#x753B;&#x89C6;&#x56FE;
 * 
 * @param view
 */
public static void showAnimatedView(View view) {
    if (PRE_HC &amp;&amp; view != null)
        view.setPadding(0, 0, 0, 0);
}

/**
 * &#x663E;&#x793A;&#x952E;&#x76D8;dialog
 * 
 * @param dialog
 */
public static void showSoftKeyboard(Dialog dialog) {
    dialog.getWindow().setSoftInputMode(4);
}

/**
 * &#x5207;&#x6362;&#x952E;&#x76D8;
 * 
 * @param view
 */

public static void toogleSoftKeyboard(Context context, View view) {
    ((InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE))
            .toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}

/**
 * &#x5224;&#x65AD;&#x662F;&#x5426;&#x6A2A;&#x5C4F;
 * 
 * @return
 */
public static boolean isLandscape(Context context) {
    boolean flag;
    if (context.getResources().getConfiguration().orientation == 2)
        flag = true;
    else
        flag = false;
    return flag;
}

/**
 * &#x5224;&#x65AD;&#x662F;&#x5426;&#x7AD6;&#x5C4F;
 * 
 * @return
 */

public static boolean isPortrait(Context context) {
    boolean flag = true;
    if (context.getResources().getConfiguration().orientation != 1)
        flag = false;
    return flag;
}

/**
 * &#x5224;&#x65AD;&#x662F;&#x5426;&#x5E73;&#x677F;
 * 
 * @return
 */

public static boolean isTablet(Context context) {
    if (_isTablet == null) {
        boolean flag;
        if ((0xf &amp; context.getResources().getConfiguration().screenLayout) &gt;= 3)
            flag = true;
        else
            flag = false;
        _isTablet = Boolean.valueOf(flag);
    }
    return _isTablet.booleanValue();
}

/**
 * &#x5224;&#x65AD;&#x662F;&#x5426;&#x6709;sd&#x5361;
 * 
 * @return
 */

public static boolean isSdcardReady() {
    return Environment.MEDIA_MOUNTED.equals(Environment
            .getExternalStorageState());
}

/**
 * &#x5224;&#x65AD;&#x7CFB;&#x7EDF;&#x8BED;&#x8A00;&#x56FD;&#x5BB6;
 * 
 * @return
 */
public static String getCurCountryLan(Context context) {
    return context.getResources().getConfiguration().locale.getLanguage()
            + &quot;-&quot;
            + context.getResources().getConfiguration().locale.getCountry();
}

/**
 * &#x5224;&#x65AD;&#x662F;&#x5426;&#x4E2D;&#x6587;&#x7B80;&#x4F53;&#xFF08;CN&#xFF09;&#x56FD;&#x5BB6;&#x4E2D;&#x56FD;
 * 
 * @return
 */

public static boolean isZhCN(Context context) {
    String lang = context.getResources().getConfiguration().locale
            .getCountry();
    if (lang.equalsIgnoreCase(&quot;CN&quot;)) {
        return true;
    }
    return false;
}

/**
 * &#x83B7;&#x53D6;&#x4E24;&#x4E2A;&#x6570;&#x7684;&#x767E;&#x5206;&#x6BD4;
 * 
 * @param p1
 * @param p2
 * @return
 */
public static String percent(double p1, double p2) {
    String str;
    double p3 = p1 / p2;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMinimumFractionDigits(5);// &#x4FDD;&#x7559;&#x7684;&#x5C0F;&#x6570;&#x4F4D;&#x6570;(&#x7CBE;&#x5EA6;)
    str = nf.format(p3);
    return str;
}

public static String percent2(double p1, double p2) {
    String str;
    double p3 = p1 / p2;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMinimumFractionDigits(0);
    str = nf.format(p3);
    return str;
}

/**
 * &#x6253;&#x5F00;&#x672C;app&#x5728;&#x5E94;&#x7528;&#x5546;&#x5E97;&#x7684;&#x9875;&#x9762;
 * 
 * @param context
 */
public static void openAppInMarket(Context context) {

    if (context != null) {
        String pckName = context.getPackageName();
        try {
            String str = &quot;market://details?id=&quot; + pckName;
            Intent localIntent = new Intent(&quot;android.intent.action.VIEW&quot;);
            localIntent.setData(Uri.parse(str));
            context.startActivity(localIntent);

        } catch (Exception ex) {

        }
    }
}

/**
 * &#x5168;&#x5C4F;&#x663E;&#x793A;&#xFF0C;&#x53BB;&#x6389;&#x9876;&#x90E8;&#x72B6;&#x6001;&#x680F;
 * 
 * @param activity
 */
public static void setFullScreen(Activity activity) {
    WindowManager.LayoutParams params = activity.getWindow()
            .getAttributes();
    params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    activity.getWindow().setAttributes(params);
    activity.getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

/**
 * &#x5173;&#x95ED;&#x5168;&#x5C4F;&#x663E;&#x793A;
 * 
 * @param activity
 */
public static void cancelFullScreen(Activity activity) {
    WindowManager.LayoutParams params = activity.getWindow()
            .getAttributes();
    params.flags &amp;= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
    activity.getWindow().setAttributes(params);
    activity.getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

/**
 * &#x5F97;&#x5230;&#x5E94;&#x7528;&#x5305;&#x540D;
 * 
 * @param pckName
 * @return
 */
public static PackageInfo getPackageInfo(Context context, String pckName) {
    try {
        return context.getPackageManager().getPackageInfo(pckName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(&quot;&quot;, e.getMessage());
    }
    return null;
}

/**
 * &#x83B7;&#x53D6;&#x7248;&#x672C;&#x540D;&#x79F0;
 * 
 * @return
 */
public static String getVersionName(Context context) {
    String name = &quot;&quot;;
    try {
        name = context.getPackageManager().getPackageInfo(
                context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException ex) {
        name = &quot;&quot;;
    }
    return name;
}

/**
 * &#x5B89;&#x88C5;apk
 * 
 * @param context
 * @param file
 */
public static void installAPK(Context context, File file) {
    if (file == null || !file.exists())
        return;
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file),
            &quot;application/vnd.android.package-archive&quot;);
    context.startActivity(intent);
}

/**
 * &#x83B7;&#x5F97;&#x5B89;&#x8F6C;&#x7684;apk
 * 
 * @param file
 * @return
 */
public static Intent getInstallApkIntent(File file) {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file),
            &quot;application/vnd.android.package-archive&quot;);
    return intent;
}

/**
 * &#x6253;&#x7535;&#x8BDD;
 * 
 * @param context
 * @param number
 */
public static void openDial(Context context, String number) {
    Uri uri = Uri.parse(&quot;tel:&quot; + number);
    Intent it = new Intent(Intent.ACTION_DIAL, uri);
    context.startActivity(it);
}

/**
 * &#x53D1;&#x77ED;&#x4FE1;
 * 
 * @param context
 * @param smsBody
 * @param tel
 */

public static void openSMS(Context context, String smsBody, String tel) {
    Uri uri = Uri.parse(&quot;smsto:&quot; + tel);
    Intent it = new Intent(Intent.ACTION_SENDTO, uri);
    it.putExtra(&quot;sms_body&quot;, smsBody);
    context.startActivity(it);
}

public static void openDail(Context context) {
    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

public static void openSendMsg(Context context) {
    Uri uri = Uri.parse(&quot;smsto:&quot;);
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

/**
 * &#x8C03;&#x7528;&#x7CFB;&#x7EDF;&#x76F8;&#x673A;
 * 
 * @param context
 */
public static void openCamera(Context context) {
    Intent intent = new Intent(); // &#x8C03;&#x7528;&#x7167;&#x76F8;&#x673A;
    intent.setAction(&quot;android.media.action.STILL_IMAGE_CAMERA&quot;);
    intent.setFlags(0x34c40000);
    context.startActivity(intent);
}

/**
 * &#x83B7;&#x53D6;&#x79FB;&#x52A8;&#x8BBE;&#x5907;&#x6807;&#x8BC6;&#x7801; &#x9700;&#x8981;&#x6743;&#x9650;android.permission.READ_PHONE_STATE
 * 
 * @return
 */
public static String getIMEI(Context context) {
    TelephonyManager tel = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    return tel.getDeviceId();
}

/**
 * &#x83B7;&#x5F97;&#x624B;&#x673A;&#x578B;&#x53F7;
 * 
 * @return
 */
public static String getPhoneType() {
    return Build.MODEL;
}

/**
 * &#x6253;&#x5F00;&#x624B;&#x673A;&#x4E0A;&#x5B89;&#x88C5;&#x7684;&#x6307;&#x5B9A;&#x5305;&#x540D;&#x7684;app
 * 
 * @param context
 * @param packageName
 */
public static void openApp(Context context, String packageName) {
    Intent mainIntent = context.getPackageManager()
            .getLaunchIntentForPackage(packageName);
    if (mainIntent == null) {
        mainIntent = new Intent(packageName);
    } else {
        Log.i(TAG, &quot;Action:&quot; + mainIntent.getAction());
    }
    context.startActivity(mainIntent);
}

public static boolean openAppActivity(Context context, String packageName,
        String activityName) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    ComponentName cn = new ComponentName(packageName, activityName);
    intent.setComponent(cn);
    try {
        context.startActivity(intent);
        return true;
    } catch (Exception e) {
        return false;
    }
}

/**
 * &#x53D1;&#x9001;&#x90AE;&#x4EF6;
 * 
 * @param context
 * @param subject
 *            &#x4E3B;&#x9898;
 * @param content
 *            &#x5185;&#x5BB9;
 * @param emails
 *            &#x90AE;&#x4EF6;&#x5730;&#x5740;
 */
public static void sendEmail(Context context, String subject,
        String content, String... emails) {
    try {
        Intent intent = new Intent(Intent.ACTION_SEND);
        // &#x6A21;&#x62DF;&#x5668;
        // intent.setType(&quot;text/plain&quot;);
        intent.setType(&quot;message/rfc822&quot;); // &#x771F;&#x673A;
        intent.putExtra(Intent.EXTRA_EMAIL, emails);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, content);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}

public static boolean hasStatusBar(Activity activity) {
    WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
    if ((attrs.flags &amp; WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
        return false;
    } else {
        return true;
    }
}

/**
 * &#x8C03;&#x7528;&#x7CFB;&#x7EDF;&#x5B89;&#x88C5;&#x4E86;&#x7684;&#x5E94;&#x7528;&#x5206;&#x4EAB;
 * 
 * @param context
 * @param title
 * @param url
 */
public static void showSystemShareOption(Activity context,
        final String title, final String url) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType(&quot;text/plain&quot;);
    intent.putExtra(Intent.EXTRA_SUBJECT, &quot;&#x5206;&#x4EAB;&#xFF1A;&quot; + title);
    intent.putExtra(Intent.EXTRA_TEXT, title + &quot; &quot; + url);
    context.startActivity(Intent.createChooser(intent, &quot;&#x9009;&#x62E9;&#x5206;&#x4EAB;&quot;));
}

/**
 * &#x83B7;&#x53D6;&#x5F53;&#x524D;&#x7F51;&#x7EDC;&#x7C7B;&#x578B;
 * 
 * @return 0&#xFF1A;&#x6CA1;&#x6709;&#x7F51;&#x7EDC; 1&#xFF1A;WIFI&#x7F51;&#x7EDC; 2&#xFF1A;WAP&#x7F51;&#x7EDC; 3&#xFF1A;NET&#x7F51;&#x7EDC;
 */
public static int getNetworkType(Context context) {
    int netType = 0;
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return netType;
    }
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_MOBILE) {
        String extraInfo = networkInfo.getExtraInfo();
        if (!TextUtils.isEmpty(extraInfo)) {
            if (extraInfo.toLowerCase().equals(&quot;cmnet&quot;)) {
                netType = NETTYPE_CMNET;
            } else {
                netType = NETTYPE_CMWAP;
            }
        }
    } else if (nType == ConnectivityManager.TYPE_WIFI) {
        netType = NETTYPE_WIFI;
    }
    return netType;
}
 }</code></pre><p>##12&#x3001;&#x6253;&#x5F00;&#x5730;&#x56FE;&#x5DE5;&#x5177;&#x7C7B;<br>&#x200B;      public class OpenLocalMapUtil {</p>
<pre><code>public OpenLocalMapUtil() {
    throw new AssertionError();
}

/**
 * &#x9AD8;&#x5FB7;&#x5730;&#x56FE;&#x5E94;&#x7528;&#x662F;&#x5426;&#x5B89;&#x88C5;
 * 
 * @return
 */
public static boolean isGdMapInstalled() {
    return isInstallPackage(&quot;com.autonavi.minimap&quot;);
}

/**
 * &#x767E;&#x5EA6;&#x5730;&#x56FE;&#x5E94;&#x7528;&#x662F;&#x5426;&#x5B89;&#x88C5;
 * 
 * @return
 */
public static boolean isBaiduMapInstalled() {
    return isInstallPackage(&quot;com.baidu.BaiduMap&quot;);
}

private static boolean isInstallPackage(String packageName) {
    return new File(&quot;/data/data/&quot; + packageName).exists();
}

/**
 * &#x83B7;&#x53D6;&#x6253;&#x5F00;&#x767E;&#x5EA6;&#x5730;&#x56FE;&#x5E94;&#x7528;uri [http://lbsyun.baidu.com/index.php?title=uri/api/android]
 * 
 * @param originLat
 * @param originLon
 * @param desLat
 * @param desLon
 * @return
 */
public static String getBaiduMapUri(String originLat, String originLon,
        String originName, String desLat, String desLon,
        String destination, String region, String src) {
    String uri = &quot;intent://map/direction?origin=latlng:%1$s,%2$s|name:%3$s&quot;
            + &quot;&amp;destination=latlng:%4$s,%5$s|name:%6$s&amp;mode=driving&amp;region=%7$s&amp;src=%8$s#Intent;&quot;
            + &quot;scheme=bdapp;package=com.baidu.BaiduMap;end&quot;;

    return String.format(uri, originLat, originLon, originName, desLat,
            desLon, destination, region, src);
}

/**
 * &#x83B7;&#x53D6;&#x6253;&#x5F00;&#x9AD8;&#x5FB7;&#x5730;&#x56FE;&#x5E94;&#x7528;uri
 */
public static String getGdMapUri(String appName, String slat, String slon,
        String sname, String dlat, String dlon, String dname) {
    String uri = &quot;androidamap://route?sourceApplication=%1$s&amp;slat=%2$s&amp;slon=%3$s&amp;sname=%4$s&amp;dlat=%5$s&amp;dlon=%6$s&amp;dname=%7$s&amp;dev=0&amp;m=0&amp;t=2&quot;;
    return String
            .format(uri, appName, slat, slon, sname, dlat, dlon, dname);
}

/**
 * &#x7F51;&#x9875;&#x7248;&#x767E;&#x5EA6;&#x5730;&#x56FE; &#x6709;&#x7ECF;&#x7EAC;&#x5EA6;
 * 
 * @param originLat
 * @param originLon
 * @param originName
 *            -&gt;&#x6CE8;&#xFF1A;&#x5FC5;&#x586B;
 * @param desLat
 * @param desLon
 * @param destination
 * @param region
 *            : &#x5F53;&#x7ED9;&#x5B9A;region&#x65F6;&#xFF0C;&#x8BA4;&#x4E3A;&#x8D77;&#x70B9;&#x548C;&#x7EC8;&#x70B9;&#x90FD;&#x5728;&#x540C;&#x4E00;&#x57CE;&#x5E02;&#xFF0C;&#x9664;&#x975E;&#x5355;&#x72EC;&#x7ED9;&#x5B9A;&#x8D77;&#x70B9;&#x6216;&#x7EC8;&#x70B9;&#x7684;&#x57CE;&#x5E02;&#x3002;--&gt;&#x6CE8;&#xFF1A;&#x5FC5;&#x586B;&#xFF0C;&#x4E0D;&#x586B;&#x4E0D;&#x4F1A;&#x663E;&#x793A;&#x5BFC;&#x822A;&#x8DEF;&#x7EBF;
 * @param appName
 * @return
 */
public static String getWebBaiduMapUri(String originLat, String originLon,
        String originName, String desLat, String desLon,
        String destination, String region, String appName) {
    String uri = &quot;http://api.map.baidu.com/direction?origin=latlng:%1$s,%2$s|name:%3$s&quot;
            + &quot;&amp;destination=latlng:%4$s,%5$s|name:%6$s&amp;mode=driving&amp;region=%7$s&amp;output=html&quot;
            + &quot;&amp;src=%8$s&quot;;
    return String.format(uri, originLat, originLon, originName, desLat,
            desLon, destination, region, appName);
}

/**
 * &#x767E;&#x5EA6;&#x5730;&#x56FE;&#x5B9A;&#x4F4D;&#x7ECF;&#x7EAC;&#x5EA6;&#x8F6C;&#x9AD8;&#x5FB7;&#x7ECF;&#x7EAC;&#x5EA6;
 * 
 * @param bd_lat
 * @param bd_lon
 * @return
 */
public static double[] bdToGaoDe(double bd_lat, double bd_lon) {
    double[] gd_lat_lon = new double[2];
    double PI = 3.14159265358979324 * 3000.0 / 180.0;
    double x = bd_lon - 0.0065, y = bd_lat - 0.006;
    double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI);
    double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * PI);
    gd_lat_lon[0] = z * Math.cos(theta);
    gd_lat_lon[1] = z * Math.sin(theta);
    return gd_lat_lon;
}

/**
 * &#x9AD8;&#x5FB7;&#x5730;&#x56FE;&#x5B9A;&#x4F4D;&#x7ECF;&#x7EAC;&#x5EA6;&#x8F6C;&#x767E;&#x5EA6;&#x7ECF;&#x7EAC;&#x5EA6;
 * 
 * @param gd_lon
 * @param gd_lat
 * @return
 */
public static double[] gaoDeToBaidu(double gd_lon, double gd_lat) {
    double[] bd_lat_lon = new double[2];
    double PI = 3.14159265358979324 * 3000.0 / 180.0;
    double x = gd_lon, y = gd_lat;
    double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * PI);
    double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * PI);
    bd_lat_lon[0] = z * Math.cos(theta) + 0.0065;
    bd_lat_lon[1] = z * Math.sin(theta) + 0.006;
    return bd_lat_lon;
}
}</code></pre><p>##13&#x3001;SDCard&#x5DE5;&#x5177;&#x7C7B;<br>&#x200B;      public class SDCardUtils {<br>&#x200B;    private SDCardUtils() {<br>&#x200B;        /* cannot be instantiated */<br>&#x200B;        throw new UnsupportedOperationException(&#x201C;cannot be instantiated&#x201D;);<br>&#x200B;    }</p>
<pre><code>/**
 * &#x5224;&#x65AD;SDCard&#x662F;&#x5426;&#x53EF;&#x7528;
 * 
 * @return
 */
public static boolean isSDCardEnable() {
    return Environment.getExternalStorageState().equals(
            Environment.MEDIA_MOUNTED);
}

/**
 * &#x83B7;&#x53D6;SD&#x5361;&#x8DEF;&#x5F84;
 * 
 * @return
 */
public static String getSDCardPath() {
    return Environment.getExternalStorageDirectory().getAbsolutePath()
            + File.separator;
}

/**
 * &#x83B7;&#x53D6;SD&#x5361;&#x7684;&#x5269;&#x4F59;&#x5BB9;&#x91CF; &#x5355;&#x4F4D;byte
 * 
 * @return
 */
public static long getSDCardAllSize() {
    if (isSDCardEnable()) {
        StatFs stat = new StatFs(getSDCardPath());
        // &#x83B7;&#x53D6;&#x7A7A;&#x95F2;&#x7684;&#x6570;&#x636E;&#x5757;&#x7684;&#x6570;&#x91CF;
        long availableBlocks = (long) stat.getAvailableBlocks() - 4;
        // &#x83B7;&#x53D6;&#x5355;&#x4E2A;&#x6570;&#x636E;&#x5757;&#x7684;&#x5927;&#x5C0F;&#xFF08;byte&#xFF09;
        long freeBlocks = stat.getAvailableBlocks();
        return freeBlocks * availableBlocks;
    }
    return 0;
}

/**
 * &#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x8DEF;&#x5F84;&#x6240;&#x5728;&#x7A7A;&#x95F4;&#x7684;&#x5269;&#x4F59;&#x53EF;&#x7528;&#x5BB9;&#x91CF;&#x5B57;&#x8282;&#x6570;&#xFF0C;&#x5355;&#x4F4D;byte
 * 
 * @param filePath
 * @return &#x5BB9;&#x91CF;&#x5B57;&#x8282; SDCard&#x53EF;&#x7528;&#x7A7A;&#x95F4;&#xFF0C;&#x5185;&#x90E8;&#x5B58;&#x50A8;&#x53EF;&#x7528;&#x7A7A;&#x95F4;
 */
public static long getFreeBytes(String filePath) {
    // &#x5982;&#x679C;&#x662F;sd&#x5361;&#x7684;&#x4E0B;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5219;&#x83B7;&#x53D6;sd&#x5361;&#x53EF;&#x7528;&#x5BB9;&#x91CF;
    if (filePath.startsWith(getSDCardPath())) {
        filePath = getSDCardPath();
    } else {// &#x5982;&#x679C;&#x662F;&#x5185;&#x90E8;&#x5B58;&#x50A8;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x5219;&#x83B7;&#x53D6;&#x5185;&#x5B58;&#x5B58;&#x50A8;&#x7684;&#x53EF;&#x7528;&#x5BB9;&#x91CF;
        filePath = Environment.getDataDirectory().getAbsolutePath();
    }
    StatFs stat = new StatFs(filePath);
    long availableBlocks = (long) stat.getAvailableBlocks() - 4;
    return stat.getBlockSize() * availableBlocks;
}

/**
 * &#x83B7;&#x53D6;&#x7CFB;&#x7EDF;&#x5B58;&#x50A8;&#x8DEF;&#x5F84;
 * 
 * @return
 */
public static String getRootDirectoryPath() {
    return Environment.getRootDirectory().getAbsolutePath();
}
}</code></pre><p>##14&#x3001;TimeUtils<br>&#x200B;      public class TimeUtils {</p>
<pre><code>public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat(
        &quot;yyyy-MM-dd HH:mm:ss&quot;);
public static final SimpleDateFormat DATE_FORMAT_DATE = new SimpleDateFormat(
        &quot;yyyy-MM-dd&quot;);

private TimeUtils() {
    throw new AssertionError();
}

/**
 * long time to string
 * 
 * @param timeInMillis
 * @param dateFormat
 * @return
 */
public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) {
    return dateFormat.format(new Date(timeInMillis));
}

/**
 * long time to string, format is {@link #DEFAULT_DATE_FORMAT}
 * 
 * @param timeInMillis
 * @return
 */
public static String getTime(long timeInMillis) {
    return getTime(timeInMillis, DEFAULT_DATE_FORMAT);
}

/**
 * get current time in milliseconds
 * 
 * @return
 */
public static long getCurrentTimeInLong() {
    return System.currentTimeMillis();
}

/**
 * get current time in milliseconds, format is {@link #DEFAULT_DATE_FORMAT}
 * 
 * @return
 */
public static String getCurrentTimeInString() {
    return getTime(getCurrentTimeInLong());
}

/**
 * get current time in milliseconds
 * 
 * @return
 */
public static String getCurrentTimeInString(SimpleDateFormat dateFormat) {
    return getTime(getCurrentTimeInLong(), dateFormat);
}

/**
 * UTC&#x8F6C;&#x6362;&#x4E3A;&#x672C;&#x5730;&#x65F6;&#x95F4;
 * 
 * @param pattern
 * @param dateTime
 * @return
 */
public static String utc2Local(String dateTime) {
    dateTime = DEFAULT_DATE_FORMAT.format(new Date(
            (Long.valueOf(dateTime)) * 1000));
    return dateTime;
}
}</code></pre><p>##15&#x3001;SnackbarUtil<br>&#x200B;      public class SnackbarUtil {</p>
<pre><code>public static final   int Info = 1;
public static final  int Confirm = 2;
public static final  int Warning = 3;
public static final  int Alert = 4;


public static  int red = 0xfff44336;
public static  int green = 0xff4caf50;
public static  int blue = 0xff2195f3;
public static  int orange = 0xffffc107;

/**
 * &#x77ED;&#x663E;&#x793A;Snackbar&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x989C;&#x8272;
 * @param view
 * @param message
 * @param messageColor
 * @param backgroundColor
 * @return
 */
public static Snackbar ShortSnackbar(View view, String message, int messageColor, int backgroundColor){
    Snackbar snackbar = Snackbar.make(view,message, Snackbar.LENGTH_SHORT);
    setSnackbarColor(snackbar,messageColor,backgroundColor);
    return snackbar;
}

/**
 * &#x957F;&#x663E;&#x793A;Snackbar&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x989C;&#x8272;
 * @param view
 * @param message
 * @param messageColor
 * @param backgroundColor
 * @return
 */
public static Snackbar LongSnackbar(View view, String message, int messageColor, int backgroundColor){
    Snackbar snackbar = Snackbar.make(view,message, Snackbar.LENGTH_LONG);
    setSnackbarColor(snackbar,messageColor,backgroundColor);
    return snackbar;
}

/**
 * &#x81EA;&#x5B9A;&#x4E49;&#x65F6;&#x5E38;&#x663E;&#x793A;Snackbar&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x989C;&#x8272;
 * @param view
 * @param message
 * @param messageColor
 * @param backgroundColor
 * @return
 */
public static Snackbar IndefiniteSnackbar(View view, String message, int duration, int messageColor, int backgroundColor){
    Snackbar snackbar = Snackbar.make(view,message, Snackbar.LENGTH_INDEFINITE).setDuration(duration);
    setSnackbarColor(snackbar,messageColor,backgroundColor);
    return snackbar;
}

/**
 * &#x77ED;&#x663E;&#x793A;Snackbar&#xFF0C;&#x53EF;&#x9009;&#x9884;&#x8BBE;&#x7C7B;&#x578B;
 * @param view
 * @param message
 * @param type
 * @return
 */
public static Snackbar ShortSnackbar(View view, String message, int type){
    Snackbar snackbar = Snackbar.make(view,message, Snackbar.LENGTH_SHORT);
    switchType(snackbar,type);
    return snackbar;
}

/**
 * &#x957F;&#x663E;&#x793A;Snackbar&#xFF0C;&#x53EF;&#x9009;&#x9884;&#x8BBE;&#x7C7B;&#x578B;
 * @param view
 * @param message
 * @param type
 * @return
 */
public static Snackbar LongSnackbar(View view, String message, int type){
    Snackbar snackbar = Snackbar.make(view,message, Snackbar.LENGTH_LONG);
    switchType(snackbar,type);
    return snackbar;
}

/**
 * &#x81EA;&#x5B9A;&#x4E49;&#x65F6;&#x5E38;&#x663E;&#x793A;Snackbar&#xFF0C;&#x53EF;&#x9009;&#x9884;&#x8BBE;&#x7C7B;&#x578B;
 * @param view
 * @param message
 * @param type
 * @return
 */
public static Snackbar IndefiniteSnackbar(View view, String message, int duration, int type){
    Snackbar snackbar = Snackbar.make(view,message, Snackbar.LENGTH_INDEFINITE).setDuration(duration);
    switchType(snackbar,type);
    return snackbar;
}

//&#x9009;&#x62E9;&#x9884;&#x8BBE;&#x7C7B;&#x578B;
private static void switchType(Snackbar snackbar, int type){
    switch (type){
        case Info:
            setSnackbarColor(snackbar,blue);
            break;
        case Confirm:
            setSnackbarColor(snackbar,green);
            break;
        case Warning:
            setSnackbarColor(snackbar,orange);
            break;
        case Alert:
            setSnackbarColor(snackbar, Color.YELLOW,red);
            break;
    }
}

/**
 * &#x8BBE;&#x7F6E;Snackbar&#x80CC;&#x666F;&#x989C;&#x8272;
 * @param snackbar
 * @param backgroundColor
 */
public static void setSnackbarColor(Snackbar snackbar, int backgroundColor) {
    View view = snackbar.getView();
    if(view!=null){
        view.setBackgroundColor(backgroundColor);
    }
}

/**
 * &#x8BBE;&#x7F6E;Snackbar&#x6587;&#x5B57;&#x548C;&#x80CC;&#x666F;&#x989C;&#x8272;
 * @param snackbar
 * @param messageColor
 * @param backgroundColor
 */
public static void setSnackbarColor(Snackbar snackbar, int messageColor, int backgroundColor) {
    View view = snackbar.getView();
    if(view!=null){
        view.setBackgroundColor(backgroundColor);
        ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(messageColor);
    }
}

/**
 * &#x5411;Snackbar&#x4E2D;&#x6DFB;&#x52A0;view
 * @param snackbar
 * @param layoutId
 * @param index &#x65B0;&#x52A0;&#x5E03;&#x5C40;&#x5728;Snackbar&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;
 */
public static void SnackbarAddView(Snackbar snackbar, int layoutId, int index) {
    View snackbarview = snackbar.getView();
    Snackbar.SnackbarLayout snackbarLayout=(Snackbar.SnackbarLayout)snackbarview;

    View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId,null);

    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    p.gravity= Gravity.CENTER_VERTICAL;

    snackbarLayout.addView(add_view,index,p);
}
 }</code></pre><p>#&#x611F;&#x8C22;<br>[<a href="https://github.com/Trinea/android-common/tree/master/src/cn/trinea/android/common][http://www.jianshu.com/p/cd1e80e64311]:Android" target="_blank" rel="noopener">https://github.com/Trinea/android-common/tree/master/src/cn/trinea/android/common][http://www.jianshu.com/p/cd1e80e64311]:Android</a> Snackbar&#x82B1;&#x5F0F;&#x4F7F;&#x7528;&#x6307;&#x5357;</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/08/21/Android-动画初探/" rel="next" title="Android 动画初探">
                <i class="fa fa-chevron-left"></i> Android 动画初探
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/08/21/Android观察者模式初探/" rel="prev" title="Android观察者模式初探">
                Android观察者模式初探 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Silence潇湘夜雨</p>
              <p class="site-description motion-element" itemprop="description">Android开发一枚</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">55</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/muyishuangfeng" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/1e2eec6f972c" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/58df0abf61ff4b006b115e43" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-star"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://twitter.com/yangke20792452" target="_blank" title="Twitter">
                      
                        <i class="fa fa-fw fa-twitter"></i>Twitter</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li></ol><li class="nav-item nav-level-2"><a class="nav-link" href="#2、应用市场管理类"><span class="nav-number"></span> <span class="nav-text">2、应用市场管理类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、Toast工具类（不建议使用，请看另外一篇-Android-自定义Toast，并且勘误"><span class="nav-number"></span> <span class="nav-text">3、Toast工具类（不建议使用，请看另外一篇[Android 自定义Toast，并且勘误</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4、KeyBoardUtils"><span class="nav-number"></span> <span class="nav-text">4、KeyBoardUtils</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5、AES工具类"><span class="nav-number"></span> <span class="nav-text">5、AES工具类</span></a></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Silence潇湘夜雨</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">114.8k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  <!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618},"display":{"superSample":2,"width":150,"height":300,"position":"right","hOffset":0,"vOffset":-20},"mobile":{"show":false},"react":{"opacityDefault":0.5,"opacityOnHover":0.5},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
